<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
    <meta charset="utf-8"/>
    <title>劲松商城后台</title>
    <div th:include="Admin/public/Common::head"></div>
    <script type="text/javascript">
        $(function (){
            $(".fengying").click(function (){
                var id=$(this).attr("id");
                var pn=$(this).attr("pn");
                swal({
                    title: "确定封禁此用户?",
                    text: "一旦封禁该用户就无法登录",
                    icon: "warning",
                    buttons: ["我再想想┭┮﹏┭┮", "确定封禁！"],
                    dangerMode: true,
                    showCancelButton: true,
                })
                    .then((willDelete) => {
                        if (willDelete) {
                            $.ajax({
                                url:"http://localhost:8080/admin/userstatus",
                                type:"POST",
                                data: {id:id},
                                success:function (data){
                                    swal("此用户已经封禁", {icon: "success",}).then(function (){
                                        location.href="http://localhost:8080/admin/user?pn="+pn;
                                    });
                                }
                            })
                        } else {
                            swal("想好了再点哟");
                        }
                    });
            })
            $(".jiefeng").click(function (){
                var id=$(this).attr("id");
                var pn=$(this).attr("pn");
                swal({
                    title: "确定解封?",
                    text: "解封之后此用户便可正常使用",
                    icon: "warning",
                    buttons: ["我再想想┭┮﹏┭┮", "确定解封！"],
                    dangerMode: true,
                    showCancelButton: true,
                })
                    .then((willDelete) => {
                        if (willDelete) {
                            $.ajax({
                                url:"http://localhost:8080/admin/userstatus",
                                type:"POST",
                                data: {id:id},
                                success:function (data){
                                    swal("此用户已解封", {icon: "success",}).then(function (){
                                        location.href="http://localhost:8080/admin/user?pn="+pn;
                                    });
                                }
                            })
                        } else {
                            swal("想好了再点哟");
                        }
                    });
            })
        })
    </script>
</head>
<body>
<div class="main-wrap">
    <div th:include="Admin/public/Common::menu"></div>
    <div class="content-wrap">
        <div th:replace="Admin/public/Common::header"></div>
        <main class="main-cont content mCustomScrollbar">
            <div class="page-wrap">
                <!--开始::内容-->
                <section class="page-hd">
                    <header>
                        <h2 class="title"><i class="fa  fa-user ">&nbsp;</i>用户管理</h2>
                    </header>
                    <hr>
                </section>
                <table class="table table-bordered table-striped table-hover">
                    <thead>
                    <tr>
                        <th>用户id</th>
                        <th>用户名</th>
                        <th>邮箱</th>
                        <th>昵称</th>
                        <th>余额</th>
                        <th>用户状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="cen" th:each="user:${pages.list}">
                        <td th:text="${user.id}"></td>
                        <td><a href="#" th:text="${user.username}" style="color: #2E9EFE"></a></td>
                        <td th:text="${user.email}"></td>
                        <td th:text="${user.nickname}"></td>
                        <td th:text="'￥'+${user.account}" style="color:gold;"></td>
                        <td th:if="${user.status==1}" th:text="正常" style="color: green"></td>
                        <td th:if="${user.status==0}" th:text="封禁中" style="color: red"></td>
                        <td>
                            <button th:if="${user.status}==1" class="btn btn-info-outline radius size-l fengying" th:id="${user.id}" th:pn="${pages.pageNum}">封禁</button>
                            <button th:if="${user.status}==0"class="btn btn-danger-outline radius size-xl jiefeng" th:id="${user.id}" th:pn="${pages.pageNum}">解封</button>
                        </td>
                    </tr>
                    </tbody>
                </table>
                <!--开始::结束-->
                <center>
                    <ul class="pagination justify-content-center">
                        <li class="page-item"><a href="#" th:href="@{/admin/user(pn=${pages.getPrePage()})}">上一页</a></li>
                        <li class="page-item" th:each="num:${pages.getNavigatepageNums()}">
                            <a th:if="${num==pages.getPageNum()}" href="#" th:text="${num}"
                               th:href="@{/admin/user(pn=${num})}" style="color: blue"></a>
                            <a th:if="${num!=pages.getPageNum()}" href="#" th:text="${num}"
                               th:href="@{/admin/user(pn=${num})}"></a>
                        </li>
                        <li class="page-item"><a href="#" th:href="@{/admin/user(pn=${pages.getNextPage()})}">下一页</a></li><br>
                    </ul>
                    <p th:text="当前+${pages.getPageNum()}+页+','+总共+${pages.getPages()}+页+','+总+${pages.getTotal()}+条记录"></p>
                </center>
            </div>
        </main>
        <div th:replace="Admin/public/Common::footer"></div>
    </div>
</div>
</body>
</html>
